using System;

namespace BeeTest
{
	public class ReturnWhenState<T0, T1, T2, T3>
	{
		#region Fields & Properties

		internal T0 state0;
		internal T1 state1;
		internal T2 state2;
		internal T3 state3;

		#endregion


		#region Constructors

		public ReturnWhenState(T0 s0, T1 s1, T2 s2, T3 s3)
		{
			this.state0 = s0;
			this.state1 = s1;
			this.state2 = s2;
			this.state3 = s3;
		}

		#endregion


		#region Operations

		public WhenState<TR> When<TR>(Func<T0, T1, T2, T3, TR> whenFunc)
		{
			try
			{
				var ret					= whenFunc(this.state0, this.state1, this.state2, this.state3);
				var state				= new WhenState<TR>(ret);
				return state;
			}
			catch(Exception exc)
			{
				return new WhenState<TR>(exc);
			}
		}


		public WhenState<TR> When<TP0, TR>(Func<T0, T1, T2, T3, TP0, TR> whenFunc, TP0 arg0)
		{
			try
			{
				var ret					= whenFunc(this.state0, this.state1, this.state2, this.state3, arg0);
				var state				= new WhenState<TR>(ret);
				return state;
			}
			catch(Exception exc)
			{
				return new WhenState<TR>(exc);
			}
		}


		public WhenState<TR> When<TP0, TP1, TR>(Func<T0, T1, T2, T3, TP0, TP1, TR> whenFunc, TP0 arg0, TP1 arg1)
		{
			try
			{
				var ret					= whenFunc(this.state0, this.state1, this.state2, this.state3, arg0, arg1);
				var state				= new WhenState<TR>(ret);
				return state;
			}
			catch(Exception exc)
			{
				return new WhenState<TR>(exc);
			}
		}


		public WhenState<TR> When<TP0, TP1, TP2, TR>(Func<T0, T1, T2, T3, TP0, TP1, TP2, TR> whenFunc, TP0 arg0, TP1 arg1, TP2 arg2)
		{
			try
			{
				var ret					= whenFunc(this.state0, this.state1, this.state2, this.state3, arg0, arg1, arg2);
				var state				= new WhenState<TR>(ret);
				return state;
			}
			catch(Exception exc)
			{
				return new WhenState<TR>(exc);
			}
		}


		public WhenState<TR> When<TP0, TP1, TP2, TP3, TR>(Func<T0, T1, T2, T3, TP0, TP1, TP2, TP3, TR> whenFunc, TP0 arg0, TP1 arg1, TP2 arg2, TP3 arg3)
		{
			try
			{
				var ret					= whenFunc(this.state0, this.state1, this.state2, this.state3, arg0, arg1, arg2, arg3);
				var state				= new WhenState<TR>(ret);
				return state;
			}
			catch(Exception exc)
			{
				return new WhenState<TR>(exc);
			}
		}


		public WhenState<TR> When<TP0, TP1, TP2, TP3, TP4, TR>(Func<T0, T1, T2, T3, TP0, TP1, TP2, TP3, TP4, TR> whenFunc, TP0 arg0, TP1 arg1, TP2 arg2, TP3 arg3, TP4 arg4)
		{
			try
			{
				var ret					= whenFunc(this.state0, this.state1, this.state2, this.state3, arg0, arg1, arg2, arg3, arg4);
				var state				= new WhenState<TR>(ret);
				return state;
			}
			catch(Exception exc)
			{
				return new WhenState<TR>(exc);
			}
		}



		#endregion
	}	
}

